﻿namespace Command.CommunityToolkit.Log4Net;

/// <summary>
/// 日志配置
/// </summary>
public static class Log4NetConfig
{
       
    /// <summary>
    /// 增加Log4Net日志
    /// </summary>
    /// <param name="serviceCollection"></param>
    /// <param name="configuration"></param>
    /// <exception cref="Exception"></exception>
    /// <remarks>
    /// 指定自定义配置
    ///       "Log4Net": {
    ///         "RepositoryName": "NETCoreRepository",
    ///         "ConfigFilePath": "Log4Net/log4net.config"
    ///       }
    /// </remarks>
    public static IServiceCollection AddLog4Net(this IServiceCollection serviceCollection, IConfiguration? configuration=null)
    {
        var configFilePath =Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Log4Net\\log4net.config");
        var file = new FileInfo(configFilePath);
        XmlConfigurator.Configure(file);
        serviceCollection.AddSingleton(LogManager.GetLogger( "Info"));
        return serviceCollection;
    }
}